package com.wx.soft.contoller.common;

import com.wx.sys.model.SysUser;
import com.wx.util.Constants;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by king-pc on 2018/12/7.
 */
public class BaseController {

    /**
     * 将user信息放入session
     * @param request
     * @param user
     */
    public void putUserToSession(HttpServletRequest request,SysUser user){
        HttpSession session = request.getSession();
        session.setAttribute(Constants.SESSION_USER,user);
    }

    /**
     * 从session获取用户信息
     * @param request
     * @return
     */
    public SysUser getSessionUser(HttpServletRequest request){
        SysUser user = (SysUser)request.getSession().getAttribute(Constants.SESSION_USER);
        return user;
    }

    /**
     * 获取当前登录用户id
     * @param request
     * @return
     */
    public String getCurUserId(HttpServletRequest request){
        SysUser user = (SysUser)request.getSession().getAttribute(Constants.SESSION_USER);
        if(user!=null){
            return user.getId();
        }
        return null;
    }

}
